//#define __DEBUG__
// by Xeno
#define THIS_FILE "x_revive\xr_f\fn_dorevive.sqf"
#include "xr_macros.sqf"

__TRACE("start");
private ["_ma", "_endtime"];
__pSetVar [QGVARXR(pisinaction), true];
__pSetVar [QGVARXR(stop_revive), false];
_ma = "ainvpknlmstpslaywrfldnon_medic";
player playMove _ma;
_endtime = time + 12;
// TODO: cancel revive does not work, the animation won't stop. damn. switchmove "" is a nada :(
//_cancelrevaction = player addAction ["<t color='#FF0000'>Cancel Revive</t>", {_this call FUNCXR(cancelrevive)}, [], -1];
waitUntil {animationState player == _ma || {!alive player} || {time > _endtime}};
waitUntil {animationState player != _ma || {!alive player} || {__pGetVar(GVARXR(stop_revive))} || {time > _endtime}};
//player removeAction _cancelrevaction;
__pSetVar [QGVARXR(pisinaction), false];
if (__pGetVar(GVARXR(stop_revive))) exitWith {
	[QGVARXR(swmnon), player] call d_fnc_NetCallEvent;
};
if (time > _endtime) exitWith {};
if (alive player && {alive __pGetVar(GVARXR(cursorTarget))}) then {
	if (GVARXR(pl_can_revive)) then {
		if (GVARXR(help_bonus) > 0 && {GVARXR(max_lives) != -1}) then {
			if (!d_with_ranked) then {
				hintSilent format [(localize "STR_DOM_MISSIONSTRING_915"), GVARXR(help_bonus)];
			} else {
				hintSilent format [(localize "STR_DOM_MISSIONSTRING_916"), GVARXR(help_bonus), d_ranked_a select 21];
				["d_pas", [player, d_ranked_a select 21]] call d_fnc_NetCallEventCTS;
			};
			_lives = __pGetVar(GVARXR(lives));
			_lives = _lives + GVARXR(help_bonus);
			__TRACE_1("","_lives");
			__pSetVar [QGVARXR(lives), _lives];
			["d_crl", [getPlayerUID player, _lives]] call d_fnc_NetCallEventCTS;
		};
		 __pGetVar(GVARXR(cursorTarget)) setVariable [QGVARXR(pluncon), false, true];
		if (GVARXR(revivemsg)) then {
			[QGVARXR(msg), [GVARXR(name_player), name __pGetVar(GVARXR(cursorTarget)), side (group player)]] call d_fnc_NetCallEventToClients;
			systemChat format [(localize "STR_DOM_MISSIONSTRING_914a"), name __pGetVar(GVARXR(cursorTarget))];
		};
		//TYRGHEN
		if (GVARXR(revive_score_bonus) > 0) then {
			["d_pas", [player, GVARXR(revive_score_bonus)]] call d_fnc_NetCallEventCTS;
			systemChat format [(localize "STR_DOM_MISSIONSTRING_2020"), GVARXR(revive_score_bonus)];
		};
	} else {
		[QGVARXR(cpr), [__pGetVar(GVARXR(cursorTarget))]] call d_fnc_NetCallEventSTO;
	};
};
__TRACE("end");